<template>
  <div class="askRend">
    <header>
      <i class="iconfont icon-angle-left"></i>
      <h3>求购</h3>
      <p>
        <i class="iconfont icon-gengduo"></i>
        <i class="iconfont icon-play1"></i>
      </p>
    </header>
    <main>
      <div class="nav">
        <van-dropdown-menu>
          <van-dropdown-item
            title="房产类型"
            v-model="value1"
            :options="option.option1"
            @change="handleChange"
          ></van-dropdown-item>
          <van-dropdown-item
            title="区域选择"
            v-model="value2"
            :options="option.option2"
            @change="handleChanges"
          ></van-dropdown-item>
        </van-dropdown-menu>
      </div>
      <div class="content">
        <dl v-for="(v, i) in arr.length ? arr : list" :key="i">
          <dt>
            <li>
              <img :src="v.userImg" alt="" />
              <p>
                <span>{{ v.name }}</span> <span>{{ v.time }}</span>
              </p>
            </li>
            <p>{{ v.title }}--{{v.roomType}}</p>
          </dt>
          <dd>
            <p>
              <span>意向区域：{{ v.area }}</span
              ><span
                >意向价格：<b>{{ v.price }}/月</b></span
              >
            </p>
            <p>
              <i class="iconfont icon-xiaoxi" @click="goDetail(v)"></i>
              <i class="iconfont icon-dianhua" @click="goCall"></i>
            </p>
          </dd>
        </dl>
      </div>
    </main>
  </div>
</template>

<script>
import axios from 'axios'
import { defineComponent, ref, reactive } from 'vue'

export default defineComponent({
  name: 'askRend',
  setup () {
    const value1 = ref(0)
    const value2 = ref('a')

    const option = reactive({
      option1: [
        { text: '房产类型', value: 0 },
        { text: '多层住宅', value: 1 },
        { text: '高层住宅', value: 2 },
        { text: '小高层住宅', value: 3 },
        { text: '商铺/门面房', value: 4 },
        { text: '厂房', value: 5 },
        { text: '写字楼', value: 6 },
        { text: '独院/别墅', value: 7 },
        { text: '车库', value: 8 }
      ],
      option2: [
        { text: '区域选择', value: 'a' },
        { text: '海淀区', value: 'b' },
        { text: '奉贤区', value: 'c' },
        { text: '昌平区', value: 'd' },
        { text: '浦东区', value: 'e' }
      ]
    })

    return {
      option,
      value1,
      value2
    }
  },

  data () {
    return {
      list: [],
      arr: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    handleChanges (value) {
      if (value === 'b') { /// 区域选择
        this.arr = this.list.filter(item => item.area === '海淀区')
      } else if (value === 'c') {
        this.arr = this.list.filter(item => item.area === '奉贤区')
      } else if (value === 'd') {
        this.arr = this.list.filter(item => item.area === '昌平区')
      } else if (value === 'e') {
        this.arr = this.list.filter(item => item.area === '浦东区')
      } else {
        this.arr = []
        this.getList()
      }
    },
    handleChange (value) {
      if (value === 1) { /// 房产类型
        this.arr = this.list.filter(item => item.roomType === '多层住宅')
      } else if (value === 2) {
        this.arr = this.list.filter(item => item.roomType === '高层住宅')
      } else if (value === 3) {
        this.arr = this.list.filter(item => item.roomType === '小高层住宅')
      } else if (value === 4) {
        this.arr = this.list.filter(item => item.roomType === '商铺/门面房')
      } else {
        this.arr = []
        this.getList()
      }
    },
    getList () {
      axios.get('/getbuyHoust').then((res) => {
        console.log(res, 'newHouse')
        this.list = res.data.data
      })
    },
    goDetail (v) {
      window.sessionStorage.setItem('obj', JSON.stringify(v))
      this.$router.push('/response')
    },
    goCall () {
      console.log(1234)
      this.$router.push('/contact')
    }
  }
})
</script>

<style lang='scss' scoped>
.askRend {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  header {
    width: 100%;
    height: 45px;
    background-color: skyblue;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    color: #fff;
    h3 {
      font-weight: normal;
    }
    p {
      width: 80px;
      padding: 2px 10px;
      display: flex;
      justify-content: space-around;
      border: 1px solid #eee;
      border-radius: 15px;
    }
  }
}
main {
  flex: 1;
  overflow-y: scroll;
  background-color: #eee;
  .nav {
    width: 100%;
    height: 50px;
    position: sticky;
    top: 0;
    left: 0;
  }
}
.content {
  width: 100%;
  height: auto;
  dl {
    width: 100%;
    height: 120px;
    border-bottom: 1px solid #eee;
    padding: 0 5px;
    background-color: #fff;
    margin-bottom: 15px;
    dt {
      width: 100%;
      height: 80px;
      border-bottom: 1px solid #eee;
      img {
        width: 35px;
        height: 35px;
        margin: 0 10px;
        border-radius: 50%;
      }
      li {
        height: 45px;
        display: flex;
        align-items: center;
        p {
          flex: 1;
          display: flex;
          justify-content: space-between;
          padding: 0 5px;
        }
      }
      p {
        height: 35px;
        line-height: 35px;
      }
    }
    dd {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      p {
        font-size: 15px;
        span {
          margin: 0 5px;
          b {
            color: #f00;
            font-size: 13px;
          }
        }
        i {
          width: 30px;
          padding: 5px;
          border-radius: 50%;
          margin: 0 3px;
          background-color: pink;
          color: #f00;
          text-align: center;
          border: 1px solid #eee;
          display: inline-block;
        }
      }
    }
  }
}
</style>
